package cn.schoolwow.quickdao.test.module.business.user.ddl.testcase;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickdao.domain.database.parent.DatabaseType;
import cn.schoolwow.quickdao.domain.entity.Entity;
import cn.schoolwow.quickdao.domain.entity.Property;
import cn.schoolwow.quickdao.domain.entity.PropertyOption;
import cn.schoolwow.quickdao.domain.transaction.Transaction;
import cn.schoolwow.quickdao.test.entity.User;
import cn.schoolwow.quickdao.test.module.business.user.ddl.flow.column.CreateNumberColumnFlow;
import cn.schoolwow.quickdao.test.module.business.user.dml.user.flow.add.RebuildUserFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import org.junit.Assert;

public class CreateNumberColumnTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowContext.executeFlowList(new RebuildUserFlow(), new CreateNumberColumnFlow());
        checkResult(flowContext);
    }

    @Override
    public String name() {
        return "用户表添加工号字段用例";
    }

    private void checkResult(FlowContext flowContext){
        DAO dao = flowContext.checkInstanceData(DAO.class);
        PropertyOption numberPropertyOption = (PropertyOption) flowContext.checkData("numberPropertyOption");

        Property numberProperty = dao.getProperty(User.class, "number");
        Assert.assertEquals(numberPropertyOption.column, numberProperty.column);
        Assert.assertTrue(numberPropertyOption.columnType.contains(numberProperty.columnType));
        Assert.assertEquals(numberPropertyOption.notNull, numberProperty.notNull);
    }
}
